.TH std::ignore 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ignore \- std::ignore

.SH Synopsis
   Defined in header <tuple>
   const /*unspecified*/ ignore;             \fI(since C++11)\fP
                                             \fI(until C++17)\fP
   inline constexpr /*unspecified*/ ignore;  \fI(since C++17)\fP

   An object of unspecified type such that any value can be assigned to it with no
   effect. Intended for use with std::tie when unpacking a std::tuple, as a placeholder
   for the arguments that are not used.

   While the behavior of std::ignore outside of std::tie is not formally specified,
   some code guides recommend using std::ignore to avoid warnings from unused return
   values of [[nodiscard]] functions.

.SH Possible implementation

   namespace detail {
   struct ignore_t
   {
       template <typename T>
       constexpr // required since C++14
       void operator=(T&&) const noexcept {}
   };
   }
   inline constexpr detail::ignore_t ignore; // 'const' only until C++17

.SH Example

    1. Demonstrates the use of std::ignore together with a [[nodiscard]] function.
    2. Unpacks a std::pair<iterator, bool> returned by std::set::insert(), but only
       saves the boolean.

// Run this code

 #include <iostream>
 #include <set>
 #include <string>
 #include <tuple>

 [[nodiscard]] int dontIgnoreMe()
 {
     return 42;
 }

 int main()
 {
     std::ignore = dontIgnoreMe();

     std::set<std::string> set_of_str;
     bool inserted = false;
     std::tie(std::ignore, inserted) = set_of_str.insert("Test");
     if (inserted)
         std::cout << "Value was inserted successfully\\n";
 }

.SH Output:

 Value was inserted successfully

.SH See also

   tie     creates a tuple of lvalue references or unpacks a tuple into individual
   \fI(C++11)\fP objects
           \fI(function template)\fP
